package com.hy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.hy.base.BaseInfoProperties;
import com.hy.mapper.InterviewRecordMapper;
import com.hy.mapper.InterviewRecordMapperCustom;
import com.hy.pojo.InterviewRecord;
import com.hy.pojo.vo.InterviewRecordVO;
import com.hy.service.InterviewRecordService;
import com.hy.utils.PagedGridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class InterviewRecordServiceImpl extends BaseInfoProperties implements InterviewRecordService {

    @Autowired
    private InterviewRecordMapper interviewRecordMapper;
    @Autowired
    private InterviewRecordMapperCustom interviewRecordMapperCustom;

    @Override
    public void save(InterviewRecord record) {
        interviewRecordMapper.insert(record);
    }

    /**
     * 判断该用户是否已经提交过面试记录
     *
     * @param candidateId
     * @return
     */
    @Override
    public boolean isCandidateRecordExist(String candidateId) {
        List<InterviewRecord> list = interviewRecordMapper.selectList(
                new QueryWrapper<InterviewRecord>().eq("candidate_id", candidateId));

        if (list != null && list.size() > 0) {
            return true;
        }
        return false;
    }

    /**
     * 查询面试记录列表
     *
     * @param realName
     * @param mobile
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PagedGridResult queryList(String realName, String mobile, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        HashMap<String, Object> map = new HashMap<>();
        map.put("realName", realName);
        map.put("mobile", mobile);
        List<InterviewRecordVO> list = interviewRecordMapperCustom.queryInterviewRecordList(map);
        return setterPagedGrid(list, page);
    }
}
